package bishi;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

// 要筛选字符串列表中长度大于6的字符串并按长度降序排序
public class demo1 {

    public static void main(String[] args) {
//        List<String> list =  List.of("hello","world", "longerstring", "short");
        List<String> list = Arrays.asList("hello", "world", "longerstring", "short", "evenlongertext");

        List<String> collect = list.stream().filter(s -> s.length() > 6)
                .sorted((a, b) -> Integer.compare(b.length(), a.length()))
                .collect(Collectors.toList());
        System.out.println(collect);

        List<String> collect1 = list.stream().filter(s -> s.length() > 6)
                .sorted(Comparator.comparingInt(String::length).reversed())
                .collect(Collectors.toList());
        System.out.println(collect1);
    }
}
